package com.mowh.multithreading.thread.per.message;

import java.util.concurrent.ThreadFactory;

/**
 * @author mowh1gd
 * @create 2023/11/23 11:25
 */
public class ThreadFactoryHost {
    private final Helper helper = new Helper();
    private final ThreadFactory threadFactory;

    public ThreadFactoryHost(ThreadFactory threadFactory) {
        this.threadFactory = threadFactory;
    }

    public void request(final int count, final char c) {
        System.out.println("    request(" + count + ", " + c + ")  BEGIN");
        threadFactory.newThread(//java.util.concurrent.ThreadFactory：显式创建线程。工厂方法模式：把工作内容(用Runnable实例，关注工作内容本身)与线程创建分离
                new Runnable() {
                    @Override
                    public void run() {
                        helper.handle(count, c);
                    }//工作内容
                }
        ).start();
        System.out.println("    request(" + count + ", " + c + ")  END");
    }
}
